﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.Web;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using System.Data;
using System.IO;
using MBSProcessComponent;

namespace MBS
{
    public partial class GenreWiseRevenueReport : System.Web.UI.Page
    {
        ReportDocument objReport = new ReportDocument();

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void btnReport_Click(object sender, EventArgs e)
        {
            DataSet dsReport = new DataSet();
           //DateTime StartDate = (DateTime)startDateCalendar.SelectedDate;
            DateTime EndDate;
            DateTime StartDate ;
           // DateTime StartDate = (DateTime)startDateCalendar.SelectedDate;
            //DateTime.TryParse(StartDateTextBox.Text, out StartDate);
            //DateTime.TryParse(EndDateTextBox.Text, out EndDate);
            MBSBLC.BLC blc = new MBSBLC.BLC();
            dsReport = blc.GetMovieGenreWiseReport(StartDateTextBox.Text, EndDateTextBox.Text);
            if (dsReport != null)
            {
                objReport.Load(Server.MapPath("~/CrystalReports/crpGenreWiseMovie.rpt"));
                objReport.SetDataSource(dsReport.Tables[0]);
                System.IO.MemoryStream s = (MemoryStream)objReport.ExportToStream(ExportFormatType.PortableDocFormat);
                var _with1 = HttpContext.Current.Response;
                _with1.ClearContent();
                _with1.ClearHeaders();
                _with1.ContentType = "application/pdf";
                _with1.AddHeader("Content-Disposition", "inline; filename=Report.pdf");
                _with1.BinaryWrite(s.ToArray());
                _with1.End();
                // rptDoc.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                //rptDoc.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, HttpContext.Current.Response, true, "JobOrderList Report");
                crpGenreReport.ReportSource = objReport;
            }
            else
            {
                string noReport = "Report for the selected dates is not available";
                ClientScript.RegisterStartupScript(this.GetType(), "sad", "javascript:showAlert('" + noReport + "')", true);
            }
        }
        protected void startDateCalendar_SelectionChanged(object sender, EventArgs e)
        {
            StartDateTextBox.Text = startDateCalendar.SelectedDate.ToString();
            

        }

        protected void endDateCalendar_SelectionChanged(object sender, EventArgs e)
        {
            EndDateTextBox.Text = endDateCalendar.SelectedDate.ToString();
        }
    }
}